package top.someapp.dxf2dsvg.base;

import java.nio.charset.Charset;

/**
 * @author zwz
 * Created on 2020-04-18
 */
public enum Encoding implements Description {
    GBK("GBK/codepage 936"),
    UTF8("UTF-8"),
    UNKNOWN("Unknown"),
    ;

    private final String descn;
    private Charset charset;

    Encoding(String descn) {
        this.descn = descn;
    }

    public Charset getCharset() {
        if (charset == null) {
            switch (this) {
                case GBK:
                    charset = Charset.forName("GBK");
                    break;
                case UTF8:
                    charset = Charset.forName("UTF-8");
                    break;
                case UNKNOWN:
                default:
                    charset = Charset.defaultCharset();
            }
        }
        return charset;
    }

    @Override
    public String describe() {
        return descn;
    }
}
